
Imports System
Imports System.Collections
Imports System.Data.SqlClient
Imports _2bMatesSite.Common


Namespace _2bMatesSite.BO
	''' <summary>
	''' Represents a networked friend with delayed user loading.
	''' </summary>
	Public Class NetworkFriend
		Protected userID As Integer
		Protected friendID As Integer
		Protected [friend] As User
		Protected pathLength As Integer
		' 1 means direct friend
		Protected path As ArrayList

		Public Sub New(ByVal userID As Integer, ByVal dr As SqlDataReader, ByVal parentNode As NetworkFriend)
			Me.userID = userID

			If parentNode <> Nothing Then
				path = New ArrayList(parentNode.Path)
				path.Add(parentNode.FriendID)
			Else
				path = New ArrayList()
			End If

			LoadFromReader(dr)
		End Sub

		Public Overloads Overrides Function GetHashCode() As Integer
			Return friendID
		End Function

		Public ReadOnly Property UserID() As Integer
			Get
				Return userID
			End Get
		End Property

		Public ReadOnly Property FriendID() As Integer
			Get
				Return friendID
			End Get
		End Property

		Public ReadOnly Property [Friend]() As User
			Get
				If [friend] = Nothing Then
					[friend] = Users.GetUserByID(friendID)
				End If
				Return [friend]
			End Get
		End Property

		' PathLength == 1 means it's a direct friend
		Public ReadOnly Property PathLength() As Integer
			Get
				Return pathLength
			End Get
		End Property

		Public ReadOnly Property Path() As ArrayList
			Get
				Return path
			End Get
		End Property

		Protected Sub LoadFromReader(ByVal dr As SqlDataReader)
			friendID = dr.GetInt32(dr.GetOrdinal("FriendUID"))
			pathLength = dr.GetInt32(dr.GetOrdinal("PathLength"))
		End Sub
	End Class
End Namespace






